/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef COMMAND_H
#define COMMAND_H

#include "Session.h"
#include "StringBuilder.h"
#include "myassert.h"

namespace Chronos {

class Command {
public:
    Command(const std::string& u) : usage(u) {}  
    virtual ~Command() {}
    virtual void execute(Session&) { ASSERT_FAIL(); }
    virtual void execute(Session&, const std::string&) { ASSERT_FAIL(); }
    virtual void execute(Session&, const std::string&, const std::string&) { ASSERT_FAIL(); }

    void printUsage(Session& session) const {
        session.write() << "Usage: " << usage << "\n";
    }
    std::string getUsage() const {
        return usage;
    }

private:
    std::string usage;
};


class DefaultCommand {
public:
    virtual ~DefaultCommand() {}
    virtual void execute(Session& session, const std::string& arg) = 0;
};

}

#define COMMAND_NO_ARGS(name, usage) \
class name : public Command { \
public: \
    name() : Command(usage) {} \
    virtual void execute(Session& session); \
};


#define COMMAND_ONE_ARG(name, usage) \
class name : public Command { \
public: \
    name() : Command(usage) {} \
    virtual void execute(Session& session, const std::string& arg1); \
};


#define COMMAND_TWO_ARGS(name, usage) \
class name : public Command { \
public: \
    name() : Command(usage) {} \
    virtual void execute(Session& session, const std::string& arg1, const std::string& arg2); \
};

#endif

